Copyright: ® Copyright 1994, The Bridge, Inc.


Shaded Forms - Contents
 Shaded Forms

Project Shade.Mak demonstrates a method of "shading" a form.  The form's appearance is similiar to the shaded background in Microsoft setup programs.

Contents

The Form

The DoShade Subroutine

The DoName Subroutine

Inc.
199 California Drive
Millbrae, CA  94030
CompuServe 71662,205
415-697-2730
Fax: 415-692-3921
Copyright 1994

Last Updated: September 29, 1994


 The Form

Set the form's background to the "darkest" shading color.  This helps avoid a "bright white" spot when the form is resized.

The shade is created in the Form_Resize routine.  I have tried using the Form_Paint routine but got unreliable results.  However; the Form_Paint event is preferred because it is faster.  The problem: After displaying this help file the shaded form would automatically become active.

If you use Form_Resize to do the shading then the form's AutoRedraw property must be set to True.


The DoShade Subroutine
 DoShade Subroutine

The subroutine is adapted from code found in the Microsoft Developer Network News, September 1994 issue, volume 3, number 5, page 6, written by Rick Raddatz.

Key Points

I added the save and reset code.  Note: The order of resetting variables effects ScaleHeight.

Sub DoShade (TheForm As Form)
    Dim ds, dm, dw, sm, sh	'save these settings
    Dim i As Integer	'for next loop
    ds = TheForm.DrawStyle	'save 'em
    dm = TheForm.DrawMode
    dw = TheForm.DrawWidth
    sm = TheForm.ScaleMode
    sh = TheForm.ScaleHeight
    TheForm.DrawStyle = Inside_Solid	'use this style
    TheForm.DrawMode = Copy_Pen	'this mode
    TheForm.DrawWidth = 2	'required for dithering
    TheForm.ScaleMode = Pixels	'mode
    TheForm.ScaleHeight = 256
    For i = 0 To 255	'now do it
      TheForm.Line (0, i)-(TheForm.Width, i + 1), RGB(0, 0, 255 - i), B
    Next
    TheForm.DrawStyle = ds	'restore the settings
    TheForm.DrawMode = dm
    TheForm.DrawWidth = dw
    TheForm.ScaleHeight = sh	'must be restored before ScaleMode
    TheForm.ScaleMode = sm
End Sub


 The DoName Subroutine

I found it necessary to set the ZOrder in this subroutine.  I don't know why exactly.  You may be able to leave it out.

Sub DoName (TheForm As Form, TheName As String)
    Dim x, y	'print here
    TheForm.ZOrder 0	'needed to print over drawn colors
    TheForm.ForeColor = RGB(32, 32, 32)	'very dark gray
    TheForm.FontName = "Arial"	'the font
    TheForm.FontSize = 48	'some nice large size

    x = 200	'x offset, start printing here
    y = 100	'y offset
    TheForm.CurrentX = x	'set cursor!
    TheForm.CurrentY = y
    TheForm.Print TheName;	'print it

    TheForm.ForeColor = RGB(255, 255, 255)	'white
    TheForm.CurrentX = x - 35	'upper left highlight color
    TheForm.CurrentY = y - 45
    TheForm.Print TheName;	'print white

    TheForm.ForeColor = &HFFFF&	'nice yellow
    TheForm.CurrentX = x - 25	'left shoulder light source
    TheForm.CurrentY = y - 35
    TheForm.Print TheName;
End Sub

You may have to change the font name - or do some checking first to make sure the user has an "Arial" font installed.